//
// Created by 吴锐 on 2022/3/3.
//

#include "iostream"
#include "vector"
#include "algorithm"

using namespace std;

void test01() {
    vector<int> v;

    v.push_back(10);
    v.push_back(40);
    v.push_back(30);
    v.push_back(40);
    v.push_back(20);
    v.push_back(40);

    int num = count(v.begin(), v.end(), 40);
    cout << "40的元素个数为: " << num << endl;
}

class Person {
public:
    string name;
    int age;

    Person(string name, int age) {
        this->name = name;
        this->age = age;
    }

    bool operator==(const Person &p) {
        if (this->age == p.age) {
            return true;
        } else {
            return false;
        }
    }
};

void test02() {
    vector<Person> v;

    Person p1("刘备", 35);
    Person p2("关羽", 35);
    Person p3("张飞", 35);
    Person p4("赵云", 30);
    Person p5("曹操", 40);
    Person p6("牛马", 18);

    v.push_back(p1);
    v.push_back(p2);
    v.push_back(p3);
    v.push_back(p4);
    v.push_back(p5);
    v.push_back(p6);

    Person p("锐神", 35);

    int num = count(v.begin(), v.end(), p);
    cout << "和诸葛亮同岁数的人有" << num << "个" << endl;
}

int main() {
//    test01();
    test02();
    return 0;
}